<template>
  <!-- 报修评价页面 -->
  <view>
    <view style="margin: 30rpx;">
      <!-- 星级 -->
      <view class="title"  style="font-size: larger;
                                  border-bottom: 1rpx solid #bec1ca;">评价星级</view>
      <view style="background-color: #FFFFFF;
                   padding-top: 30rpx;
                   display: flex;
                   justify-content: space-around;">
        <u-rate :count="count" v-model="starvalue" gutter="10" size="80rpx"></u-rate>
        <view style="padding-top: 20rpx;width: 120rpx;color: #959595;">{{startext[starvalue-1]}}</view>
      </view>
      <!-- 描述 -->
      <view class="title"  style="font-size: larger;
                                  border-bottom: 1rpx solid #bec1ca;">评价描述</view>
      <view>
        <u--textarea v-model="assessdetail" placeholder="请输入评价描述" count></u--textarea>
      </view>
      <view class="submit" @click="assessRepair">提交</view>

    </view>




  </view>
</template>

<script>
  export default {
    data() {
      return {
        count: 5,
        starvalue: 5,
        startext:['非常差','差','一般','好','非常好'],
        assessdetail: '',
        repair:{},
      };
    },
    onLoad(option){
      this.getRepairById(option.id);
    },
    methods:{
      async getRepairById(id){
        const {data: res} = await uni.$http.post('/repair/getrepairbyid',id)
        if (res.status !== 200) return uni.$showMsg()
        console.log(res.data)
        this.repair=res.data;
      },
      async assessRepair(){
        var assessRepair=this.repair;
        assessRepair.status='已评价';
        assessRepair.evaluateStar=this.starvalue;//评价星级
        assessRepair.evalueteDetail=this.assessdetail;//评价描述
        // runningRepair.evaluateTime=uni.$getDateTime();//调用自己封装好的获取当前时间并格式化的方法
        assessRepair.evaluateTime=uni.$getDateTime(new Date());//评价时间
        const {data: res} = await uni.$http.put('/repair/updaterepair',assessRepair)
        if (res.status !== 200) return uni.$showMsg()
        console.log(res.data.isok)
        if(res.data.isok===false){
          uni.$showMsg("出问题啦~ 再试一次吧~ ")//原因是加了乐观锁，就是为了防止两个人重复接单的问题
        }else{
          uni.$showMsg("叮~ 您的评价已送给维修师傅")
          setTimeout(() => {
            uni.switchTab({
              url: '/pages/repair/repair'
            })
          }, 2000)
        }
      }
    },
  }
</script>

<style lang="scss">
  .title {
    background-color: #FFFFFF;
    padding-top: 30rpx;
    padding-left: 20rpx;
  }
  .title>view{
    display: flex;
    margin: 20rpx;
    padding-bottom: 30rpx;
  }

  .submit {
    background-color: #1599FD;
    color: #FFFFFF;
    font-weight: bold;
    text-align: center;
    border-radius: 15rpx;
    line-height: 100rpx;
    height: 100rpx;
    margin-top: 300rpx;
  }
</style>
